#!/usr/bin/python


def read_data(fd):
    '''Given the file descriptor fd reads data from it.'''
    data = []
    for line in fd.readlines():
        line = line.strip()
        if not line or line.startswith('#'):
            continue
        else:
            yield line


def load_graph(fd):
    edges = {}
    for line in read_data(fd):
        line = [x.strip() for x in line.split(' ') if x and x != '->']
        u, v, weight = line[0], line[1], int(line[2])
        edges[u, v] = edges[v, u] = weight
    return edges
